package com.resafety.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class PaymentService {
    public String Paymentinfo_Ok(Integer id){
        return "线程池 ："+Thread.currentThread().getName()+" Paymentinfo_Ok: id:"+id;
    }
    @HystrixCommand(fallbackMethod = "Paymentinfo_timerOut_Error",commandProperties = {
            //设置这个线程的超时时间是3s，3s内是正常的业务逻辑，超过3s调用fallbackMethod指定的方法进行处理
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String Paymentinfo_timerOut(Integer id){
        try {
            TimeUnit.SECONDS.sleep(5);
        }catch (InterruptedException e){e.printStackTrace();}
        return "线程池 ："+Thread.currentThread().getName()+" Paymentinfo_timerOut: id:"+id;
    }
    public  String Paymentinfo_timerOut_Error(Integer id){
        return "失败！";
    }
}
